#include "../Header Files/CGame.h"
#include "../Header Files/CIntroCinematicState.h"

CGame::CGame()
{
}

CGame* CGame::GetInstance()
{
	static CGame _cGameInstance;
	return &_cGameInstance;
}

void CGame::Initialize()
{
	//start this puppy up in the intro cinematic!
	CIntroCinematicState* state = new CIntroCinematicState();
	state->Initialize();
	CGame::GetInstance()->PushState(state);
}

void CGame::PushState(IBaseState* pState)
{
	pState->Enter();
	m_vStates.push_back(pState);
}

void CGame::PopState()
{
	if(m_vStates.size() > 0)
	{
		IBaseState* state = m_vStates.back();
		m_vStates.pop_back();
		state->Exit();
	}
}
	
bool CGame::Update(float fDT)
{
	for (unsigned int i = 0; i < m_vStates.size(); ++i)
	{
		if (m_vStates[i]->GetIfStateIsActive())
		{
			m_vStates[i]->Update(fDT);
		}
	}
	return true;
}
	
void CGame::Shutdown()
{
	if (m_vStates.size() > 0)
	{
		for (unsigned int i(0); i < m_vStates.size(); ++i)
		{
			delete m_vStates[i];
			m_vStates[i] = NULL;
		}
		m_vStates.clear();
	}
}